<?php
header("Content-Type:application/json;charset=utf-8");
header("Access-Control-Allow-Origin:*");
if ($_SERVER["REQUEST_METHOD"]=="POST"){
    //1.准备链接数据库的配置信息
    $host="127.0.0.1";
    $name="root";
    $pwd="";
    $port="3306";
    $db="mia";
    //2.创建链接
    $conn=new mysqli($host,$name,$pwd,$db,$port);
    //3.设置链接字符集
    mysqli_query($conn,"SET NAMES UTF8");
    //4.SQL语句
    $sql="SELECT * FROM `carts` WHERE uId='".$_POST["uid"]."'";
    //5.执行sql语句
    $result=$conn->query($sql);
    $resultArray=array();
    if($result->num_rows>0){
        while($row = $result->fetch_assoc()) {
            array_push($resultArray,$row);
            echo json_encode($resultArray).'';
        }
    }else{
        echo '0';
    }
    $conn->close();
}